#!usr/bin/node

const mysql = require('mysql2/promise'),
      {con,ResData} = require('./common.js');


async function getAuthorsByPage(page,limit) {
  const res = new ResData();

  const sql = `select * from authors order by id limit ${(page-1)*limit},${limit};`,
  sqlCount = `select count(id) as count from authors;`;

  let [rows] = await con.execute(sql);
  res.data = rows;

  //rows = await con.query(sqlCount);
  //res.data = rows[0].count;

  return res;
};

module.exports = {
  getAuthorsByPage
};
